package com.lxb.myforum.service.spec

import java.util.ArrayList

import javax.persistence.criteria.CriteriaBuilder
import javax.persistence.criteria.CriteriaQuery
import javax.persistence.criteria.Predicate
import javax.persistence.criteria.Root

import org.springframework.data.jpa.domain.Specification

import com.lxb.myforum.pojo.Dictionary

class DictionarySpec(private val dict: Dictionary) : Specification<Dictionary> {

    override fun toPredicate(root: Root<Dictionary>, query: CriteriaQuery<*>, cb: CriteriaBuilder): Predicate? {
        val predicates = ArrayList<Predicate>()
        //		if (dict.getId() != null) {
        //			predicates.add(cb.or(cb.equal(root.get("id"), dict.getParentId())));
        //		}
        if (dict.parentId != null) {
            predicates.add(cb.equal(root.get<Any>("parentId"), dict.parentId))
        }

        query.where(*predicates.toTypedArray())
        return null
    }
}
